home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Examples / Skeleton / UViewSkeleton.cp < prev    next >
Encoding:
Text File  |  1996-04-04  |  7.0 KB  |  207 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UViewSkeleton.cp
  3. // Copyright © 1991-96 by Apple Computer, Inc. All rights reserved. 
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UVIEWSKELETON__
  7. #include "UViewSkeleton.h"
  8. #endif
  9.  
  10. #ifndef __UMACAPPUTILITIES__
  11. #include "UMacAppUtilities.h"
  12. #endif
  13.  
  14. #ifndef __UDOCUMENTSKELETON__
  15. #include "UDocumentSkeleton.h"
  16. #endif
  17.  
  18. #ifndef __UTRACKERSKELETON__
  19. #include "UTrackerSkeleton.h"
  20. #endif
  21.  
  22. #ifndef __UMENUMGR__
  23. #include "UMenuMgr.h"
  24. #endif
  25.  
  26. #ifndef __FONTS__
  27. #include "Fonts.h"
  28. #endif
  29.  
  30. //----------------------------------------------------------------------------------------
  31. // Constants:
  32.  
  33. const CommandNumber cCommandHandledByView = 402;
  34.     
  35. //========================================================================================
  36. // Global Initialization Procedure
  37. //========================================================================================
  38. #undef Inherited
  39.  
  40. //----------------------------------------------------------------------------------------
  41. // InitUViewSkeleton: 
  42. //----------------------------------------------------------------------------------------
  43. #pragma segment DlgInit
  44.  
  45. void InitUViewSkeleton()
  46. {
  47.     // So the linker doesn't dead strip class info 
  48.     MA_REGISTER_CLASS(TViewSkeleton);
  49. } // InitUViewSkeleton 
  50.  
  51.  
  52. //========================================================================================
  53. // CLASS TViewSkeleton
  54. //========================================================================================
  55. #undef Inherited
  56. #define Inherited TView
  57.  
  58. #pragma segment AOpen
  59. MA_DEFINE_CLASS_M1(TViewSkeleton, Inherited);
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // TViewSkeleton constructor 
  63. //----------------------------------------------------------------------------------------
  64. #pragma segment AOpen
  65.  
  66. TViewSkeleton::TViewSkeleton()  
  67. {
  68.     fDocumentSkeleton = NULL;
  69. } // TViewSkeleton::TViewSkeleton 
  70.  
  71. //----------------------------------------------------------------------------------------
  72. // TViewSkeleton destructor
  73. //----------------------------------------------------------------------------------------
  74. #pragma segment MADestructorRes
  75.  
  76. TViewSkeleton::~TViewSkeleton()
  77. {
  78. }
  79.     
  80. //----------------------------------------------------------------------------------------
  81. // TViewSkeleton::IViewSkeleton: 
  82. //----------------------------------------------------------------------------------------
  83. #pragma segment AOpen
  84.  
  85. void TViewSkeleton::IViewSkeleton(TDocumentSkeleton* itsDocumentSkeleton,
  86.                                         TView* itsSuperView,
  87.                                          const VPoint& itsLocation,
  88.                                          const VPoint& itsSize)
  89. {
  90.     this->IView(itsDocumentSkeleton,itsSuperView,itsLocation,itsSize,sizeFixed, sizeFixed);
  91.     
  92.     fDocumentSkeleton = itsDocumentSkeleton;
  93. } // TViewSkeleton::IViewSkeleton 
  94.  
  95. //----------------------------------------------------------------------------------------
  96. // TViewSkeleton::Draw: 
  97. //----------------------------------------------------------------------------------------
  98. #pragma segment ARes
  99.  
  100. void TViewSkeleton::Draw(const VRect& area) // Override 
  101. {
  102.     const VCoordinate boxHeight = 50;
  103.     const long nRows = fSize.v / boxHeight;
  104.     const VPoint increment(fSize.h / nRows, boxHeight);
  105.  
  106.     VRect aVRect(gZeroVPt, increment);                // construct the rect at top left of view.
  107.     
  108.     PenNormal();    
  109.     PenPat(&qd.ltGray);
  110.  
  111.     for (long row = 0; row < nRows; row++)
  112.     {
  113.         if (!(area & aVRect).Empty())
  114.             PaintRect(&ViewToQDRect(aVRect));
  115.             
  116.         if (!row)                                    // draw title over first rect, regardless of rect's visibility.
  117.         {
  118.             VRect stringRect(aVRect);
  119.             stringRect.right += 400;
  120.             if (!(area & stringRect).Empty())
  121.             {
  122.                 TextFont(times);                        // a nice outline font
  123.                 TextSize((short)stringRect.GetLength(vSel));
  124.                 MADrawString("Skeleton Application",ViewToQDRect(stringRect),teFlushDefault,TRUE);
  125.             }
  126.         }
  127.         
  128.         aVRect += increment;                        // move rect after drawing.
  129.     }
  130. } // TViewSkeleton::Draw 
  131.  
  132. //----------------------------------------------------------------------------------------
  133. // TViewSkeleton::DoMenuCommand: This method is overridden to handle menu items which are
  134. // enabled when this view is in the target chain. In this example, this is true when the
  135. // window containing this view is the active window. The inherited method should always be
  136. // called so that MacApp can allow successor objects in the target chain (i.e. document
  137. // and application) to handle THEIR menu items.
  138. //----------------------------------------------------------------------------------------
  139. #pragma segment ASelCommand
  140.  
  141. void TViewSkeleton::DoMenuCommand(CommandNumber aCommandNumber) // Override 
  142. {
  143.     switch (aCommandNumber) 
  144.     {
  145.         case cCommandHandledByView :
  146.             SysBeep(2);
  147.             break;
  148.             
  149.         default:
  150.             Inherited::DoMenuCommand(aCommandNumber);
  151.             break;
  152.     }
  153. } // TViewSkeleton::DoMenuCommand 
  154.  
  155. //----------------------------------------------------------------------------------------
  156. // TViewSkeleton::DoPostCreate: 
  157. //----------------------------------------------------------------------------------------
  158. #pragma segment AOpen
  159.     
  160. void TViewSkeleton::DoPostCreate(TDocument* itsDocument) // Override 
  161. {
  162.     Inherited::DoPostCreate(itsDocument);
  163.     
  164.     fDocumentSkeleton = (TDocumentSkeleton*) itsDocument;
  165. } // TViewSkeleton::DoPostCreate 
  166.     
  167. //----------------------------------------------------------------------------------------
  168. // TViewSkeleton::DoSetupMenus: This method is overridden to enable menu items which
  169. // should be enabled when this view is in the target chain. MacApp initially disables all
  170. // menu items, then lets the objects in the target chain enable those items they handle.
  171. //
  172. // A view is generally in the target chain when its window is the active window, and the
  173. // view or one of its subviews is designated as the target of that window. In this
  174. // example, the window's resource specifies the skeleton view as the target.
  175. // 
  176. // The inherited method is called so that objects further up the target chain (the
  177. // scroller, window, document and application) can set up THEIR menus.
  178. //----------------------------------------------------------------------------------------
  179. #pragma segment ARes
  180.             
  181. void TViewSkeleton::DoSetupMenus() // Override 
  182. {
  183.     Inherited::DoSetupMenus();
  184.     Enable(cCommandHandledByView,TRUE);
  185. //    EnableCheck(cCommandHandledByView,true,true);
  186. } // TViewSkeleton::DoSetupMenus 
  187.  
  188. //----------------------------------------------------------------------------------------
  189. // TViewSkeleton::DoMouseCommand: 
  190. //----------------------------------------------------------------------------------------
  191. #pragma segment ASelCommand
  192.  
  193. void TViewSkeleton::DoMouseCommand(VPoint& theMouse,
  194.                                   TToolboxEvent* /* event */,
  195.                                   CPoint /* hysteresis */)    // Override
  196. {
  197.     TTrackerSkeleton* aTracker = new TTrackerSkeleton;
  198.  
  199.     aTracker->ITrackerSkeleton(fDocumentSkeleton, this, this->GetScroller(FALSE), theMouse);
  200.     this->PostCommand(aTracker);
  201. } // TViewSkeleton::DoMouseCommand 
  202.  
  203. //----------------------------------------------------------------------------------------
  204. // End of UViewSkeleton.cp
  205.  
  206. #pragma segment Inline
  207.